package com.lamer.console.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo());
    }

    private ApiInfo apiInfo(){
        ValueOperations<String, String> operations = redisTemplate.opsForValue();
        return new ApiInfoBuilder()
                .title(operations.get("SWAGGER.TITLE"))
                .description(operations.get("SWAGGER.DESCRIPTION"))
                .version(operations.get("SWAGGER.VERSION"))
                .contact(new Contact(operations.get("SWAGGER.NAME"), operations.get("SWAGGER.URL"), operations.get("SWAGGER.EMAIL")))
                .build();
    }

}
